package com.shop2cn.iapi.shenqisettlement.testcase;

import com.shop2cn.iapi.shenqisettlement.parameter.MerchantUpdatePaymentInfoReq;
import com.shop2cn.iapi.shenqisettlement.service.MerchantUpdatePaymentInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.shenqisettlement.DistributorAgencyOfflineMonthBill;
import com.ymttest.database.sqlwapper.shenqisettlement.DistributorAgencyOfflineMonthBillWrapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

import org.junit.*;
import org.junit.experimental.categories.Category;

/**
 * 根据国家获取汇率 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_MerchantUpdatePaymentInfo {
	
	private static MerchantUpdatePaymentInfoReq merchantUpdatePaymentInfoReq;
	private static MerchantUpdatePaymentInfoCall merchantUpdatePaymentInfoCall;
	
	private DistributorAgencyOfflineMonthBillWrapper distributorAgencyOfflineMonthBillWrapper = new DistributorAgencyOfflineMonthBillWrapper();

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新支付凭证-线下结算");
	}

	@Before
	public void caseUp() {
		merchantUpdatePaymentInfoReq = new MerchantUpdatePaymentInfoReq();
		merchantUpdatePaymentInfoCall = new MerchantUpdatePaymentInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(merchantUpdatePaymentInfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	public void verify() {

		DistributorAgencyOfflineMonthBill actualObject = distributorAgencyOfflineMonthBillWrapper
				.selectByPrimaryKey(merchantUpdatePaymentInfoReq
						.getBillId());

		Logger.verifyEquals(
				merchantUpdatePaymentInfoReq.getDistributorId(),
				actualObject.getDistributor_id(), "验证Distributor_id");
		Logger.verifyEquals(merchantUpdatePaymentInfoReq.getOperatorId(),
				actualObject.getPaid_operator(), "验证Paid_operator");
		DataUtil.verifyDateEquals(
				merchantUpdatePaymentInfoReq.getPaidTime(),
				actualObject.getPaid_time(), "验证Paid_time");
		Logger.verifyEquals(merchantUpdatePaymentInfoReq.getVoucherUrl(),
				actualObject.getPaid_voucher(), "验证Paid_voucher");
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_MerchantUpdatePaymentInfo_001() {
		Logger.start(true, "更新支付凭证成功");
		try {
			
			distributorAgencyOfflineMonthBillWrapper.updatePaid(3L, 1);
			distributorAgencyOfflineMonthBillWrapper.updateReceived(3L, 0);

			merchantUpdatePaymentInfoReq.setMerchantId(500011795L);
			merchantUpdatePaymentInfoReq.setDistributorId(501565934L);
			merchantUpdatePaymentInfoReq.setOperatorId(4321L);
			merchantUpdatePaymentInfoReq.setPaidTime(YMTDateUtil.getBeforeOrNextHour(-1, YMTDateUtil.YMDHMSS));
			merchantUpdatePaymentInfoReq.setBillId(3L);
			merchantUpdatePaymentInfoReq.setVoucherUrl(TestDataManager.randomStr(5));
			
			merchantUpdatePaymentInfoCall.setData(merchantUpdatePaymentInfoReq);
			merchantUpdatePaymentInfoCall.callService();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_MerchantUpdatePaymentInfo_002() {
		Logger.start(true, "该月账单已经还未支付，不能更新");
		try {
			
			distributorAgencyOfflineMonthBillWrapper.updatePaid(3L, 0);

			merchantUpdatePaymentInfoReq.setMerchantId(500011795L);
			merchantUpdatePaymentInfoReq.setDistributorId(501565934L);
			merchantUpdatePaymentInfoReq.setOperatorId(4321L);
			merchantUpdatePaymentInfoReq.setPaidTime(YMTDateUtil.getBeforeOrNextHour(-1, YMTDateUtil.YMDHMSS));
			merchantUpdatePaymentInfoReq.setBillId(3L);
			merchantUpdatePaymentInfoReq.setVoucherUrl(TestDataManager.randomStr(5));
			
			merchantUpdatePaymentInfoCall.setData(merchantUpdatePaymentInfoReq);
			merchantUpdatePaymentInfoCall.callService();
			
			Logger.verifyEquals("该月账单已经还未支付，不能更新",
					merchantUpdatePaymentInfoCall.getMsg(), "验证msg");
			Logger.verifyEquals(3,
					merchantUpdatePaymentInfoCall.getErrorCode(),
					"验证resultCode");
			Logger.verifyEquals(false,
					merchantUpdatePaymentInfoCall.getSuccess(),
					"验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_MerchantUpdatePaymentInfo_003() {
		Logger.start(true, "该月账单已经确认收款，不能更新");
		try {
			
			distributorAgencyOfflineMonthBillWrapper.updatePaid(3L, 1);
			distributorAgencyOfflineMonthBillWrapper.updateReceived(3L, 1);

			merchantUpdatePaymentInfoReq.setMerchantId(500011795L);
			merchantUpdatePaymentInfoReq.setDistributorId(501565934L);
			merchantUpdatePaymentInfoReq.setOperatorId(4321L);
			merchantUpdatePaymentInfoReq.setPaidTime(YMTDateUtil.getBeforeOrNextHour(-1, YMTDateUtil.YMDHMSS));
			merchantUpdatePaymentInfoReq.setBillId(3L);
			merchantUpdatePaymentInfoReq.setVoucherUrl(TestDataManager.randomStr(5));
			
			merchantUpdatePaymentInfoCall.setData(merchantUpdatePaymentInfoReq);
			merchantUpdatePaymentInfoCall.callService();
			
			Logger.verifyEquals("该月账单已经确认收款，不可再支付",
					merchantUpdatePaymentInfoCall.getMsg(), "验证msg");
			Logger.verifyEquals(3,
					merchantUpdatePaymentInfoCall.getErrorCode(),
					"验证resultCode");
			Logger.verifyEquals(false,
					merchantUpdatePaymentInfoCall.getSuccess(),
					"验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_MerchantUpdatePaymentInfo_004() {
		Logger.start(true, "错误的商户，无权更新支付凭证");
		try {
			
			distributorAgencyOfflineMonthBillWrapper.updatePaid(3L, 1);
			distributorAgencyOfflineMonthBillWrapper.updateReceived(3L, 0);

			merchantUpdatePaymentInfoReq.setMerchantId(1L);
			merchantUpdatePaymentInfoReq.setDistributorId(501565934L);
			merchantUpdatePaymentInfoReq.setOperatorId(4321L);
			merchantUpdatePaymentInfoReq.setPaidTime(YMTDateUtil.getBeforeOrNextHour(-1, YMTDateUtil.YMDHMSS));
			merchantUpdatePaymentInfoReq.setBillId(3L);
			merchantUpdatePaymentInfoReq.setVoucherUrl(TestDataManager.randomStr(5));
			
			merchantUpdatePaymentInfoCall.setData(merchantUpdatePaymentInfoReq);
			merchantUpdatePaymentInfoCall.callService();
			
			Logger.verifyEquals("无权操作该账单",
					merchantUpdatePaymentInfoCall.getMsg(), "验证msg");
			Logger.verifyEquals(3,
					merchantUpdatePaymentInfoCall.getErrorCode(),
					"验证resultCode");
			Logger.verifyEquals(false,
					merchantUpdatePaymentInfoCall.getSuccess(),
					"验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}